package top.cardone.api.v1.usercenter.user

import org.apache.commons.lang3.RandomStringUtils
import org.apache.commons.lang3.StringUtils
import top.cardone.context.ApplicationContextHolder
import top.cardone.context.util.MapUtils
import top.cardone.core.CodeException
import top.cardone.usercenter.service.UserService

class u0003 implements java.io.Serializable {
    def input(input) {
        def userIds = input?.userIds?.split(",")

        if (!userIds) {
            throw new CodeException("userIds required", "用户标识集合必填")
        }

        def passwordSalt = RandomStringUtils.random(16, UUID.randomUUID().toString())

        def password = ApplicationContextHolder.getBean(top.cardone.security.Descipher.class).encrypt(passwordSalt, MapUtils.getString(input, "password", "123456"))

        def userIdList = []

        for (def userId : userIds) {
            userIdList.add(["userId": userId, "password": password, "passwordSalt": passwordSalt])
        }

        ["userIds": userIdList]
    }

    def validation(input) {
    }

    def func(input) {
        ['updateCount': ApplicationContextHolder.getBean(UserService.class).updateListCache((List) input?.userIds)]
    }

    def output(output) {
        output
    }
}